package tt.dz.mvc.controller.sys;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForList;
import tt.dz.entity.system.InstructionLog;
import tt.dz.entity.system.OmsUrlTreeVO;
import tt.dz.mvc.controller.base.BaseController;
import tt.dz.service.sys.InstructionLogService;
import tt.dz.util.OmsConstant;
import tt.dz.util.StringUtil;

@Controller
@RequestMapping("instructionLog")
public class InstructionLogController extends BaseController
{
	private Log log = LogFactory.getLog(InstructionLogController.class);

	@Autowired
	private InstructionLogService insLogServiceImpl;

	@RequestMapping(value = "getList")
	@ResponseBody
	public JsonForList getList(HttpServletRequest request, HttpServletResponse response)
	{
		String charger_id = request.getParameter("charger_id");
		String transferType = request.getParameter("transfer_type");
		Integer transfer_type =  null;
		if (StringUtil.isNotBlank(transferType)) {
			transfer_type =  Integer.valueOf(transferType);
		}
		
		String frame_type = request.getParameter("frame_type");
		String ins_name = request.getParameter("ins_name");
		InstructionLog queryPo = new InstructionLog();
		queryPo.setCharger_id(charger_id);
		queryPo.setTransfer_type(transfer_type);
		queryPo.setFrame_type(frame_type);
		queryPo.setIns_name(ins_name);
		
		//模糊查询
		String searchStr = request.getParameter("searchStr");
		if (StringUtil.isNotBlank(searchStr)) {
			queryPo.setCharger_id(searchStr);
			queryPo.setFrame_type(searchStr);
			queryPo.setIns_name(searchStr);
			queryPo.setIns_content(searchStr);
		}
		int pageNo = Integer.valueOf(request.getParameter("pageNo"));//必传
		int pageSize = Integer.valueOf(request.getParameter("pageSize"));//必传
		String sortName = request.getParameter("sortName");
		
		
		int sortVal = Integer.valueOf(request.getParameter("sortVal"));
		return insLogServiceImpl.findListByPage(queryPo, pageNo, pageSize, sortName, sortVal);
//		return new JsonForList<>(list, OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}

	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "logicDel")
	@ResponseBody
	public JsonCommon logicDel(Integer id)
	{
		if(id ==null){
			return new JsonCommon<>( "400", "failOfNoParam"); 
		}
		try {
			insLogServiceImpl.logicalDel(id);
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return new JsonCommon<>( OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}
}